package top.micheal.towdemo;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @program: netty-parent
 * @description: Server
 * @author: Micheal.Wang
 * @blog: <a href="http://www.micheal.top">MichealWang</a>
 * @create: 2019-11-18 14:24
 **/
public class TestServer {

    public static void main(String[] args) {
        EventLoopGroup boosGrop = new NioEventLoopGroup(1);
        EventLoopGroup workGrop = new NioEventLoopGroup();


        try {
        ServerBootstrap bootstrap = new ServerBootstrap().channel(NioServerSocketChannel.class)
                .group(boosGrop, workGrop)
                .childHandler(new TestServerInitializer());


            ChannelFuture channelFuture = bootstrap.bind(8080).sync();
            channelFuture.channel().closeFuture().sync();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        finally {
            boosGrop.shutdownGracefully();
            workGrop.shutdownGracefully();
        }

    }
}
